#include "facemanage.h"
#include <qDebug>
facemanage::facemanage(QObject *parent) : QObject(parent)
{
    seeta::ModelSetting FDmode("C:/Users/13275/Desktop/embedded_Project/mid_File/opencv-compile-Win/seetaFace/bin/model/fd_2_00.dat",seeta::ModelSetting::GPU,0);
    seeta::ModelSetting PDmode("C:/Users/13275/Desktop/embedded_Project/mid_File/opencv-compile-Win/seetaFace/bin/model/pd_2_00_pts5.dat",seeta::ModelSetting::GPU,0);
    seeta::ModelSetting FRmode("C:/Users/13275/Desktop/embedded_Project/mid_File/opencv-compile-Win/seetaFace/bin/model/fr_2_10.dat",seeta::ModelSetting::GPU,0);
    faceengine = new seeta::FaceEngine(FDmode,PDmode,FRmode);
    faceengine->Load("./face.db");
}

facemanage::~facemanage()
{
    delete  faceengine;
}

qint64 facemanage::register_face(cv::Mat &matimg)
{
    SeetaImageData imgdata;
    imgdata.data = matimg.data;
    imgdata.width = matimg.cols;
    imgdata.height = matimg.rows;
    imgdata.channels = matimg.channels();
    int64_t faceid = faceengine->Register(imgdata);;
    if(faceid>=0)
     {
       faceengine->Save("./face.db") ;
    }

    return faceid;
}

int facemanage::query_face(cv::Mat &matimg)
{
    SeetaImageData imgdata;
    imgdata.data = matimg.data;
    imgdata.width = matimg.cols;
    imgdata.height = matimg.rows;
    imgdata.channels = matimg.channels();
    float sim=0;
    int64_t faceid;
    faceid = faceengine->Query(imgdata,&sim);
    qDebug()<<"sim="<<sim<<endl;
    if(sim>0.7)
    {
        return faceid;
    }else{
        qDebug()<< "query fail"<<endl;
        return -1;
    }

}

